You are here: Building the Model: Advanced Elements > Variables > Local Variables > Example
A plant manufactures valves of 10 different sizes, such as 10'', 20'', .... All valves are inspected at a common inspection station and then move to a dock where they are loaded onto pallets. The pallets are designed to hold only a certain size valve. Therefore, a pallet designed to hold 10'' valves can only hold 10'' valves, not 20'' valves.
Suppose a Pallet enters a multi-capacity location, Dock. Each Pallet has a different entity attribute, p_type, describing the type of valve it can hold. Valves are loaded onto the Pallet. The 10" valves must be loaded onto the pallet designed to hold the 10" valves. Therefore, the attribute value of the Valve, v_type, must match the attribute value of the Pallet, p_type. We can use local variables to accomplish this modeling task. The logic is as follows where X is a local variable:
Process Table
Entity |
Location |
Operation (min) |
---|---|---|
Valve |
Inspect |
WAIT 5 |
Pallet |
Dock |
INT X X = p_type LOAD 10 IFF X = v_type WAIT 10 |
Routing Table
Blk |
Output |
Destination |
Rule |
Move Logic |
---|---|---|---|---|
1 |
Valve |
Dock |
LOAD 1 |
MOVE FOR 2 |
1 |
Pallet |
Delivery |
FIRST 1 |
MOVE FOR 8 |
If we had not used local variables, we would need to use the following operation logic for Pallet at Dock:
As can be seen from the two examples of logic, the first example is much easier and more straight forward.
It is important to note that using "LOAD 10 IFF p_type = v_type" in the operation logic would not work for the intended purpose. Attributes referenced in IFF conditions always refer to the entity being loaded. Set the value of a local variable, X, to the pallet attribute, p_type, so it can be referenced in the LOAD statement. The pallet attribute cannot be directly referenced in the LOAD statement.
If Dock was a single capacity location, using a global variable would work the same as using a local variable. However, because Dock is a multi-capacity location, it can load valves onto multiple pallets at the same time. If a global variable was used instead of a local variable, the global variable would change each time a pallet entered Dock. If there were two different types of pallets at Dock, there would be only one type of valve loaded on the pallet because the global variable refers to both pallets.
Suppose, for example, a global variable, type, signifies the pallet attribute, p_type. We assign type=p_type at the beginning of the operation logic for location Dock. The first pallet arrives and type=3. Therefore, only valves with v_type=3 are loaded onto the pallet. Another pallet enters Dock and type=5. Now only valves with valve_type=5 are loaded onto both pallets.
Please note
Local variable notes:
1. You may not use the WAIT UNTIL statement with local variables.
2. The local variable definition only needs to appear somewhere in the logic before being referenced. The entity does not need to execute the local variable definition statement (INT, REAL).